<template>
  <div
    class="table-manage-containeer"
    :style="{ 'padding-bottom': selectionList.length > 0 ? '13px' : '0px' }"
  >
    <flexbox v-if="selectionList.length > 0" class="selection-bar">
      <div class="selected—title">
        已选中
        <span class="selected—count">{{ selectionList.length }}</span> 项
      </div>
      <flexbox class="selection-items-box">
        <template v-for="(item, index) in getSelectionHandleItemsInfo()">
          <el-button
            v-if="whetherTypeShowByPermision(item.type)"
            :icon="item.icon | wkIconPre"
            :key="index"
            type="primary"
            @click.native="selectionBarClick(item.type)"
            >{{ item.name }}</el-button
          >
        </template>
      </flexbox>
    </flexbox>
    <!-- 转移 -->
    <transfer-handle
      :crm-type="crmType"
      :selection-list="selectionList"
      :dialog-visible.sync="transferDialogShow"
      @handle="handleCallBack"
    />
    <!-- 转移讲师 -->
    <TransferTeacher
      :crm-type="crmType"
      :selection-list="selectionList"
      :dialog-visible.sync="transferTeacherDialogShow"
      @handle="handleCallBack"
    ></TransferTeacher>
    <transform-handle
      :crm-type="crmType"
      :selection-list="selectionList"
      :dialog-visible.sync="transformDialogShow"
      :transformTeacherList="transformTeacherList"
      @handle="handleCallBack"
    />
    <!-- 更改学员状态 -->
    <change-student-status-handle
      :crm-type="crmType"
      :idList="selectBatchIdList"
      :selection-list="selectionList"
      :selectIdList="selectIdList"
      :dialog-visible.sync="changeStudentStatusShow"
      @handle="handleCallBack"
    />
    <!-- 添加 移除团队成员 -->
    <teams-handle
      :crm-type="crmType"
      :title="teamsTitle"
      :selection-list="selectionList"
      :dialog-visible.sync="teamsDialogShow"
      @handle="handleCallBack"
    />
    <!-- 转移助教  -->
    <change-handle
      :crm-type="crmType"
      :selection-list="selectionList"
      :dialog-visible.sync="changeDialogShow"
      @handle="handleCallBack"
    />
    <!-- 变更风险状态 -->
    <ChangeRiskHandle
      :crm-type="crmType"
      :idList="selectBatchIdList"
      :selection-list="selectionList"
      :selectIdList="selectIdList"
      :dialog-visible.sync="changeStudentRiskShow"
      @handle="handleCallBack"
    ></ChangeRiskHandle>
  </div>
</template>

<script>
// 状态管理
import { mapGetters } from "vuex";
import { crmLargeScreenSettingAPI } from "@/api/crm/common";
// 组件
import TransferHandle from "./SelectionHandle/TransferHandle"; // 转移线索负责人
import TransferTeacher from "./SelectionHandle/transferTeacherHandle.vue"; // 转移讲师
import ChangeHandle from "./SelectionHandle/ChangeHandle"; // 转移
import OverdueHandle from "./SelectionHandle/OverdueHandle"; // 逾期状态
import TransformHandle from "./SelectionHandle/TransformHandle"; // 转化为学员
import TeamsHandle from "./SelectionHandle/TeamsHandle"; // 操作团队成员
import AllocHandle from "./SelectionHandle/AllocHandle"; // 公海分配操作
import DealStatusHandle from "./SelectionHandle/DealStatusHandle"; // 学员状态修改操作
import PutPoolHandle from "./SelectionHandle/PutPoolHandle"; // 放入公海
import ChangeStudentStatusHandle from "./SelectionHandle/ChangeStudentStatusHandle"; // 更改学员状态
import ChangeRiskHandle from "./SelectionHandle/ChangeRiskHandle"; // 变更风险

// 接口
import {
  crmLeadsTransformAPI,
  crmLeadsExcelExportAPI,
  crmLeadsDeleteAPI,
  revokeTransfer
} from "@/api/crm/leads";
import {
  crmCustomerLockAPI,
  crmCustomerExcelExportAPI,
  crmCustomerPoolExcelExportAPI,
  crmCustomerDeleteAPI,
  crmCustomerPoolDeleteAPI,
  crmCustomerReceiveAPI
} from "@/api/crm/customer";
import {
  crmContactsDeleteAPI,
  crmContactsExcelExportAPI
} from "@/api/crm/contacts";
import {
  crmBusinessDeleteAPI,
  crmBusinessExcelExportAPI
} from "@/api/crm/business";
import {
  crmContractDeleteAPI,
  crmContractExcelExportAPI
} from "@/api/crm/contract";
import {
  crmReceivablesDeleteAPI,
  crmReceivablesExcelExportAPI
} from "@/api/crm/receivables";
import { crmRefundDeleteAPI, crmRefundExcelExportAPI } from "@/api/crm/refund";
import {
  crmProductStatusAPI,
  crmProductExcelExportAPI,
  crmProductDeleteAPI
} from "@/api/crm/product";
import { crmReturnVisitDeleteAPI } from "@/api/crm/visit";
import {
  crmRoiExcelExportAPI,
  crmroiDeleteAPI,
  crmAllianceBusinessDeleteAPI
} from "@/api/crm/roiMoney";
import { crmSourcesDeleteAPI } from "@/api/crm/source";
import { crmputinStatisticsExcelExportAPI } from "@/api/crm/putinStatistics";
import {
  crmCustomerVipExcelExportAPI,
  crmCustomerVipDeleteAPI
} from "@/api/crm/vipStudents";
import {
  crmOverdueExcelExportAPI,
  crmOverdueDeleteAPI
} from "@/api/crm/overdue";
import { crmQueryBatchIdsByIdsAPI } from "@/api/crm/vipStudents";
// 方法
import { downloadExcelWithResData } from "@/utils";
import {
  queryTrainingStatusAPI,
  queryTeacherListForLeadsAPI
} from "@/api/admin/training";

export default {
  props: {
    /** 没有值就是全部类型 有值就是当个类型 */
    crmType: {
      type: String,
      default: ""
    },
    // 辅助 使用 公海没有场景
    isSeas: {
      type: Boolean,
      default: false
    },
    activeName: {
      type: String,
      default: ""
    }
  },
  components: {
    TransferHandle,
    ChangeHandle,
    OverdueHandle,
    TransformHandle,
    TeamsHandle,
    AllocHandle,
    DealStatusHandle,
    PutPoolHandle,
    ChangeStudentStatusHandle,
    ChangeRiskHandle,
    TransferTeacher
  },
  data() {
    return {
      sceneData: {
        id: "",
        bydata: "",
        name: ""
      },
      /** 勾选操作数据 */
      selectionList: [],
      transferDialogShow: false,
      transferTeacherDialogShow: false,
      changeDialogShow: false,
      changeStudentStatusShow: false,
      changeStudentRiskShow: false,
      changeRiskStauts: false,
      overdueDialogShow: false,
      transformDialogShow: false,
      teamsDialogShow: false, // 团队操作提示框
      teamsTitle: "", // 团队操作标题名
      allocDialogShow: false, // 公海分配操作提示框
      dealStatusShow: false, // 成交状态修改框
      putPoolShow: false, // 学员放入公海
      selectIdList: [],
      selectBatchIdList: [],
      isRepay: true,
      transformTeacherList: []
    };
  },
  computed: {
    ...mapGetters(["crm"])
  },
  methods: {
    /** 勾选后的表头操作 */
    headSelectionChange(array) {
      this.selectionList = array;
    },
    /** 选择了场景 */
    sceneSelect(data) {
      this.sceneData = data;
      this.$emit("scene", data);
    },
    /** 操作 */
    selectionBarClick(type) {
      if (type == "transfer") {
        // 转移
        this.transferDialogShow = true;
      } else if (type == "overdue") {
        this.overdueDialogShow = true;
      } else if (type == "changeAssistantUser") {
        this.changeDialogShow = true;
      } else if (type == "changeStudentStauts") {
        if (this.selectionList) {
          this.selectIdList = [];
          for (var i = 0; i < this.selectionList.length; i++) {
            this.selectIdList[i] = this.selectionList[i].studentId;
          }
        }
        crmQueryBatchIdsByIdsAPI(this.selectIdList).then(res => {
          this.selectBatchIdList = res.data;
        });
        this.changeStudentStatusShow = true;
      } else if (type == "changeRiskStauts") {
        if (this.selectionList) {
          this.selectIdList = [];
          for (var i = 0; i < this.selectionList.length; i++) {
            this.selectIdList[i] = this.selectionList[i].studentId;
          }
        }
        this.changeStudentRiskShow = true;
      } else if (type == "export") {
        let params = {};
        let request = null;
        if (this.isSeas) {
          request = crmCustomerPoolExcelExportAPI;
          params.poolId = this.poolId;
          params.ids = this.selectionList
            .map(item => item.customerId)
            .join(",");
        } else {
          // console.warn(this.crmType,'this.crmType','params',params,this.selectionList.map((item) => item["putinMoneyId"]),this.selectionList);
          request = {
            customer: crmCustomerExcelExportAPI,
            leads: crmLeadsExcelExportAPI,
            contacts: crmContactsExcelExportAPI,
            business: crmBusinessExcelExportAPI,
            contract: crmContractExcelExportAPI,
            receivables: crmReceivablesExcelExportAPI,
            refund: crmRefundExcelExportAPI,
            product: crmProductExcelExportAPI,
            roiMoney: crmRoiExcelExportAPI,
            crmPutinAllianceBusiness: crmRoiExcelExportAPI,
            putinStatistics: crmputinStatisticsExcelExportAPI,
            vipStudents: crmCustomerVipExcelExportAPI,
            overdue: crmOverdueExcelExportAPI
          }[this.crmType];
          if (this.crmType == "roiMoney") {
            params = this.selectionList.map(item => item["putinMoneyId"]);
          } else if (this.crmType == "putinStatistics") {
            params = {
              putinPlatform: this.selectionList
                .map(item => item["putinPlatform"])
                .toString(),
              startDate: this.searchList.date[0] || "",
              endDate: this.searchList.date[1] || ""
            };
          } else {
            params = this.selectionList.map(
              item =>
                item[
                  `${
                    this.crmType == "vipStudents" ? "student" : this.crmType
                  }Id`
                ]
            );
          }
        }
        request(params)
          .then(res => {
            setTimeout(() => {
              this.$bus.emit("document-visibility", "visible");
            }, 2500);
            this.selectionList = [];
            downloadExcelWithResData(res);
            // 清空tabel勾选项
            let table;
            this.$parent.$children.forEach(item => {
              if (item.$options && item.$options.name === "ElTable") {
                table = item;
              }
              if (table) {
                table.clearSelection();
              }
            });
            // this.changeParentStu();
          })
          .catch(() => {});
      } else if (
        type == "delete" ||
        type == "lock" ||
        type == "unlock" ||
        type == "start" ||
        type == "disable" ||
        type == "get"
      ) {
        var message = "";
        if (type == "delete") {
          message = this.isSeas
            ? "若学员下有联系人，联系人将一并删除。确定删除？"
            : `确定删除选中的${this.selectionList.length}项吗？`;
        } else if (type == "lock") {
          message = "确定要锁定这些学员吗？锁定后将不会掉入公海。";
        } else if (type == "unlock") {
          message = "确定要解锁这些学员吗？";
        } else if (type == "start") {
          message = "确定要上架这些产品吗?";
        } else if (type == "disable") {
          message = "确定要下架这些产品吗?";
        } else if (type == "get") {
          message = "确定要领取该学员吗?";
        }

        this.$confirm(message, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            console.log("总想这里-----------------------");
            this.changeParentStu();
            this.confirmHandle(type);
          })
          .catch(() => {});
      } else if (type == "transform") {
        // 转化学员操作
        queryTrainingStatusAPI().then(res1 => {
          if (res1.data == 1) {
            //训练营模式开启
            this.teamsTitle = "转化学员填写字段";
            this.transformDialogShow = true;
            queryTeacherListForLeadsAPI().then(res => {
              this.transformTeacherList = res.data.list || [];
            });
          } else {
            //训练营模式关闭
            this.$confirm(
              `确定将选中的${
                this.selectionList.length
              }项线索数据转化为学员吗？`,
              "提示",
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
              }
            )
              .then(() => {
                crmLeadsTransformAPI({
                  leadsIds: this.selectionList.map(item =>
                    parseInt(item["leadsId"])
                  )
                }).then(ress => {
                  if (ress.code == 0) {
                    this.$message({
                      type: "success",
                      message: "操作成功"
                    });
                    this.handleCallBack({ type: "transfer" });
                  } else {
                    this.$message({
                      type: "error",
                      message: res.msg
                    });
                  }
                });
              })
              .catch(() => {});
          }
        });
      } else if (type == "transcancel") {
        //取消转化
        // 取消转化学员操作
        const params = {
          leadsIds: this.selectionList.map(item =>
            parseInt(item[this.crmType + "Id"])
          )
        };
        revokeTransfer(params)
          .then(res => {
            if (res.code == 0) {
              //取消成功
              this.$message({
                type: "success",
                message: "操作成功"
              });

              this.handleCallBack({ type: "transcancel" });
            }
          })
          .catch(() => {});
      } else if (type == "add_user") {
        // 团队操作
        this.teamsTitle = "添加团队成员";
        this.teamsDialogShow = true;
      } else if (type == "delete_user") {
        // 团队操作
        this.teamsTitle = "移除团队成员";
        this.teamsDialogShow = true;
      } else if (type == "alloc") {
        // 公海分配操作
        this.allocDialogShow = true;
      } else if (type == "deal_status") {
        // 学员成交状态操作
        this.dealStatusShow = true;
      } else if (type == "put_seas") {
        // 学员放入公海
        this.putPoolShow = true;
      } else if (type == "transferTeacher") {
        this.transferTeacherDialogShow = true;
      }
    },
    // 判断是否展示
    whetherTypeShowByPermision(type) {
      if (type == "transfer") {
        if (this.crmType == "leads") {
          return this.sceneData.bydata == "transform"
            ? false
            : this.crm[this.crmType].transfer ||
                this.crm[this.crmType].transferLeadsUser;
        } else {
          return this.sceneData.bydata == "transform"
            ? false
            : this.crm[this.crmType].transfer;
        }
      } else if (type == "transform") {
        return this.sceneData.bydata == "transform"
          ? false
          : this.crm[this.crmType].transform;
      } else if (type == "export") {
        if (this.isSeas) {
          if (this.poolId) {
            return this.poolAuth.excelexport;
          }
          return this.crm.pool && this.crm.pool.excelexport;
        }
        if (this.crm[this.crmType]) {
          return this.crm[this.crmType].excelexport;
        } else {
          return true;
        }
      } else if (type == "delete") {
        if (this.isSeas) {
          if (this.poolId) {
            return this.poolAuth.delete;
          }
          return this.crm.pool && this.crm.pool.delete;
        }
        return this.crm[this.crmType].delete;
      } else if (type == "put_seas") {
        // 放入公海(学员)
        return this.crm[this.crmType].putinpool;
      } else if (type == "lock" || type == "unlock") {
        // 锁定解锁(学员)
        return this.crm[this.crmType].lock;
      } else if (type == "add_user" || type == "delete_user") {
        // 添加 移除团队成员
        return this.crm[this.crmType].teamsave;
      } else if (type == "alloc") {
        // 分配(公海)
        if (this.poolId) {
          return this.poolAuth.distribute;
        }
        return this.crm.pool && this.crm.pool.distribute;
      } else if (type == "get") {
        // 领取(公海)
        if (this.poolId) {
          return this.poolAuth.receive;
        }
        return this.crm.pool && this.crm.pool.receive;
      } else if (type == "start") {
        // 上架 下架(产品)
        for (let index = 0; index < this.selectionList.length; index++) {
          const element = this.selectionList[index];
          if (element.status == 1) {
            return false;
          }
        }
        return this.crm[this.crmType].status;
      } else if (type == "disable") {
        // 上架 下架(产品)
        for (let index = 0; index < this.selectionList.length; index++) {
          const element = this.selectionList[index];
          if (element.status == 0) {
            return false;
          }
        }
        return this.crm[this.crmType].status;
      } else if (type == "deal_status") {
        // 学员状态修改
        return this.crm[this.crmType].dealStatus;
      } else if (type == "changeAssistantUser") {
        return true;
      } else if (type == "changeStudentStauts") {
        // 变更学员状态
        return true;
      } else if (type == "changeRiskStauts") {
        // 变更风险状态
        return this.crm[this.crmType].changeRisk;
      } else if (type == "overdue") {
        return this.crm[this.crmType].overdue;
      } else if (type == "transcancel") {
        //撤销转化
        return this.crm[this.crmType].revoketransform;
      } else if (type == "transferTeacher") {
        // 转移讲师
        return this.crm[this.crmType].transferTeacher;
      }

      return true;
    },
    /** 获取展示items */
    getSelectionHandleItemsInfo() {
      const handleInfos = {
        transfer: {
          name: "转移",
          type: "transfer",
          icon: "transfer"
        },
        transform: {
          name: "转化为学员",
          type: "transform",
          icon: "transform"
        },
        transferTeacher: {
          name: "转移讲师",
          type: "transferTeacher",
          icon: "transfer"
        },
        transcancel: {
          name: "撤销转化",
          type: "transcancel",
          icon: "transcancel"
        },
        export: {
          name: "导出选中",
          type: "export",
          icon: "export"
        },
        delete: {
          name: "删除",
          type: "delete",
          icon: "delete"
        },
        put_seas: {
          name: "放入公海",
          type: "put_seas",
          icon: "seas"
        },
        changeAssistantUser: {
          name: "转移助教",
          type: "changeAssistantUser",
          icon: "transfer"
        },
        changeStudentStauts: {
          name: "变更学员状态",
          type: "changeStudentStauts",
          icon: "transfer"
        },
        changeRiskStauts: {
          name: "变更风险状态",
          type: "changeRiskStauts",
          icon: "transfer"
        },
        overdue: {
          name: "变更逾期状态",
          type: "overdue",
          icon: "transfer"
        },
        lock: {
          name: "锁定",
          type: "lock",
          icon: "lock"
        },
        unlock: {
          name: "解锁",
          type: "unlock",
          icon: "unlock"
        },
        add_user: {
          name: "添加团队成员",
          type: "add_user",
          icon: "add"
        },
        delete_user: {
          name: "移除团队成员",
          type: "delete_user",
          icon: "remove"
        },
        alloc: {
          name: "分配",
          type: "alloc",
          icon: "alloc"
        },
        get: {
          name: "领取",
          type: "get",
          icon: "receive"
        },
        start: {
          name: "上架",
          type: "start",
          icon: "shelves"
        },
        disable: {
          name: "下架",
          type: "disable",
          icon: "sold-out"
        },
        deal_status: {
          name: "更改成交状态",
          type: "deal_status",
          icon: "s-status"
        }
      };
      if (this.crmType == "leads") {
        return this.forSelectionHandleItems(handleInfos, [
          "transfer",
          "transform",
          "transcancel",
          "export",
          "delete"
        ]);
      } else if (
        this.crmType == "roiMoney" ||
        this.crmType == "crmPutinAllianceBusiness"
      ) {
        return this.forSelectionHandleItems(handleInfos, ["export", "delete"]);
      } else if (this.crmType == "putinStatistics") {
        return this.forSelectionHandleItems(handleInfos, ["export"]);
      } else if (this.crmType == "crmLargeScreenSetting") {
        return this.forSelectionHandleItems(handleInfos, ["export", "delete"]);
      } else if (this.crmType == "customer") {
        return this.forSelectionHandleItems(handleInfos, [
          "transfer",
          "export",
          "delete"
        ]);
      } else if (this.crmType == "vipStudents") {
        return this.forSelectionHandleItems(handleInfos, [
          "transfer",
          "changeAssistantUser",
          // "changeStudentStauts",
          "changeRiskStauts",
          "deal_status",
          "export",
          "delete"
        ]);
      } else if (this.crmType == "contacts") {
        return this.forSelectionHandleItems(handleInfos, [
          "transfer",
          "export",
          "delete"
        ]);
      } else if (this.crmType == "business") {
        return this.forSelectionHandleItems(handleInfos, [
          "transfer",
          "export",
          "delete",
          "add_user",
          "delete_user"
        ]);
      } else if (this.crmType == "contract") {
        if (this.activeName == "second") {
          return this.forSelectionHandleItems(handleInfos, [
            "transfer",
            "export"
          ]);
        }
        return this.forSelectionHandleItems(handleInfos, [
          "transfer",
          "transferTeacher",
          "export",
          "delete"
        ]);
      } else if (this.crmType == "receivables") {
        return this.forSelectionHandleItems(handleInfos, [
          "transfer",
          "transferTeacher",
          "export",
          "delete"
        ]);
      } else if (this.crmType == "refund") {
        if (this.activeName == "账单退款") {
          return this.forSelectionHandleItems(handleInfos, [
            "transfer",
            "transferTeacher",
            "export"
          ]);
        }
        return this.forSelectionHandleItems(handleInfos, [
          "transfer",
          "transferTeacher",
          "export",
          "delete"
        ]);
      } else if (this.crmType == "product") {
        return this.forSelectionHandleItems(handleInfos, [
          "transfer",
          "export",
          "delete",
          "start",
          "disable"
        ]);
      } else if (this.crmType == "product") {
        return this.forSelectionHandleItems(handleInfos, [
          "export",
          "start",
          "disable"
        ]);
      } else if (this.crmType == "visit") {
        return this.forSelectionHandleItems(handleInfos, ["delete"]);
      } else if (this.crmType == "customerSource") {
        return this.forSelectionHandleItems(handleInfos, ["delete"]);
      } else if (this.crmType == "overdue") {
        return this.forSelectionHandleItems(handleInfos, ["export", "delete"]);
      }
    },
    forSelectionHandleItems(handleInfos, array) {
      const tempsHandles = [];
      for (let index = 0; index < array.length; index++) {
        tempsHandles.push(handleInfos[array[index]]);
      }
      return tempsHandles;
    },
    confirmHandle(type) {
      if (type === "lock" || type === "unlock") {
        this.loading = true;
        crmCustomerLockAPI({
          status: type === "lock" ? "2" : "1", // 1是正常 2 是锁定
          ids: this.selectionList.map(item => item.customerId).join(",")
        })
          .then(res => {
            this.loading = false;
            this.$message({
              type: "success",
              message: "操作成功"
            });
            this.$emit("handle", {
              type: type
            });
          })
          .catch(() => {
            this.loading = false;
          });
      } else if (type === "transform") {
        this.loading = true;
        crmLeadsTransformAPI(this.selectionList.map(item => item.leadsId))
          .then(res => {
            this.loading = false;
            this.$message({
              type: "success",
              message: "转化成功"
            });
            // 刷新待办
            this.$store.dispatch("GetMessageNum");

            this.$emit("handle", {
              type: type
            });
          })
          .catch(() => {
            this.loading = false;
          });
      } else if (type === "start" || type === "disable") {
        this.loading = true;
        crmProductStatusAPI({
          ids: this.selectionList.map(item => item.productId),
          status: type === "start" ? "1" : "0"
        })
          .then(res => {
            this.loading = false;
            this.$message({
              type: "success",
              message: "操作成功"
            });
            this.$emit("handle", {
              type: type
            });
          })
          .catch(() => {
            this.loading = false;
          });
      } else if (type === "delete") {
        console.log("第二步，删除-");
        var ids = null;
        if (
          this.crmType == "roiMoney" ||
          this.crmType == "crmPutinAllianceBusiness"
        ) {
          ids = this.selectionList.map(item => item["putinMoneyId"]);
        } else if (
          this.crmType == "crmLargeScreenSetting" ||
          this.crmType == "customerSource"
        ) {
          ids = this.selectionList.map(item => item["id"]);
        } else {
          ids = this.selectionList.map(
            item =>
              item[
                (this.crmType == "vipStudents" ? "student" : this.crmType) +
                  "Id"
              ]
          );
        }
        const request = {
          leads: crmLeadsDeleteAPI,
          customer: this.isSeas
            ? crmCustomerPoolDeleteAPI
            : crmCustomerDeleteAPI,
          contacts: crmContactsDeleteAPI,
          business: crmBusinessDeleteAPI,
          contract: crmContractDeleteAPI,
          receivables: crmReceivablesDeleteAPI,
          refund: crmRefundDeleteAPI,
          visit: crmReturnVisitDeleteAPI,
          product: crmProductDeleteAPI,
          roiMoney: crmroiDeleteAPI,
          crmPutinAllianceBusiness: crmAllianceBusinessDeleteAPI,
          vipStudents: crmCustomerVipDeleteAPI,
          crmLargeScreenSetting: crmLargeScreenSettingAPI,
          customerSource: crmSourcesDeleteAPI,
          overdue: crmOverdueDeleteAPI
        }[this.crmType];
        const params = {};
        if (this.isSeas) {
          params.poolId = this.poolId;
        }
        params.ids = ids;
        this.loading = true;
        request(this.isSeas ? params : ids)
          .then(res => {
            this.loading = false;
            this.$message({
              type: "success",
              message: "删除成功"
            });
            this.$emit("handle", {
              type: type
            });
          })
          .catch(() => {
            this.loading = false;
          });
      } else if (type === "get") {
        // 领取
        this.loading = true;
        crmCustomerReceiveAPI({
          ids: this.selectionList.map(item => item.customerId),
          poolId: this.poolId
        })
          .then(res => {
            this.loading = false;
            this.$message({
              type: "success",
              message: "操作成功"
            });
            // 刷新待办
            this.$store.dispatch("GetMessageNum");

            this.$emit("handle", {
              type: type
            });
          })
          .catch(() => {
            this.loading = false;
          });
      }
    },
    // 子组件 回调的 结果
    handleCallBack(data) {
      console.log(data, "data-handleCallBack");
      this.$emit("handle", {
        type: data.type
      });
      this.changeParentStu();
    },
    changeParentStu() {
      this.$parent.isShow = false;
      setTimeout(() => {
        this.$parent.isShow = true;
      }, 2);
    }
  }
};
</script>

<style lang="scss" scoped>
@import "../styles/selection-bar.scss";
</style>
